<?php
require_once "config.php";
require_once 'class/class.phpmailer.php';
error_reporting(false);
$memberobj=new Member();
$offer_obj = new Offer();
$active_offers = $offer_obj->list_active_offers();
if(isset($_POST["signUpButton"]))
 {
      $en_key = '&56TCVH%#*P*W&vddbsd&^%';
        $enc = new Encryption;
        $validation_obj = new Validation();
        $validation_error = array();
        $user_values = $_POST;
       // print_r($user_values);exit;
        foreach ($user_values as $key => $value) {
            if($validation_obj->check_blank(trim($value) == true)) {
                    $validation_error[$key] = "<li class='error'>$key is blank</li>";
            }
        }


       unset($validation_error['username'],$validation_error['password'],$validation_error['terms_and_conditions']);
        if($validation_obj->validate_email($user_values['user_email']) == false) {
            $validation_error['user_email'] = "<li class='error'>Please enter a valid email address</li>";
        }

        if(trim($user_values['user_password']) == '') {
            $validation_error['user_password'] = "<li class='error'>Please enter a password</li>";
        }
        if($user_values['user_password'] != $user_values['confirm_password']) {
            $validation_error['confirm_password'] = "<li class='error'>Passwords do not match. Please try again</li>";
        }
        if($memberobj->member_exist(trim($user_values['user_email'])) != false) {
            $validation_error['user_email'] = "<li class='error'>This email address already exists. Please try again with a new address or try logging in.</li>";
        }
        if(trim($user_values['contact_number2']) == '') {
            $validation_error['contact_number2'] = "<li class='error'>Please enter your contact number</li>";
        }
        if(!isset($user_values['tc2'])) {
            $validation_error['tc2'] = "<li class='error'>You must read and agree terms and conditions to proceed</li>";
        }
        $img = new Securimage();
        $valid = $img->check($_POST['image_code']);

        if($valid == FALSE) {
          $validation_error['image_code'] = "<li class='error'>Sorry, the code you entered was invalid</li>";
        }
      //  print_r($validation_error);exit;
        if(empty($validation_error)) {
            $_SESSION['user_verification'] = 'success';
            $verify_details = array('member_email'=>$user_values['user_email'],
                'creation_date' => date('Y-m-d H:i:s'),
                'last_update' => date('Y-m-d H:i:s'),
                'status' => 'P',
                'first_name'=> $user_values['first_name2'],
                 'last_name'=> $user_values['last_name2'],
                'contact_number' => $user_values['contact_number2'],
                'member_password' => $enc->encrypt($en_key, $user_values['user_password']),
                'member_status' => 'G'

            );


            $memID=$memberobj->create_member($verify_details);
                        $_SESSION['member_id'] = $memID;
                        $_SESSION['first_name'] = $user_values['first_name2'];
                        $_SESSION['last_name'] = $user_values['last_name2'];
                        $_SESSION['member_email'] = $user_values['user_email'];
            // Encrypt the Source Text
            $encstr = $enc->encrypt($en_key, $user_values['user_email']);
            $to_name = $user_values['user_email'];
            $from_name = 'Hotel With Offers';
            $click_link = 'http://www.hotelswithoffers.com/registration_step_two.php?tmu&#61;'.urlencode($encstr);

           // $from_email = 'exceldatabank@yahoo.com';
           // $email_obj = new EmailFunc($to_name, $to_name, $from_name, $from_email);
            $email_message = "<img src='http://www.hotelswithoffers.com/images/logo.png' /><br/>";
            $email_message .= "Dear " . $to_name . ",<br/><br/>";
            $email_message .= "Thank you for verify with us. <br/>   <br/><br/>";
            $email_message .= "Regards <br/>";
            $email_message .= "hotelswithoffers   Team.\n";

            // To send HTML mail, the Content-type header must be set
            $subject = 'Email Verification from hotelswithoffers.com';

            $mail = new PHPMailer();
		$mail->IsMail();
		$mail->IsHTML(true);
                $mail->FromName = 'Hotelswithoffers';
                $mail->From = 'hotelswithoffers.com';
		$mail->AddAddress($user_values['user_email']);
                $mail->AddCC('induneth87@gmail.com');
		$mail->Subject = $subject;
		$mail->Body = $email_message;
		//print_r($mail->Send());
                  header("Location:welcome.php") ;
		if(!$mail->Send())
		{
		   echo "Error sending: " . $mail->ErrorInfo;;
		}
                else{
                    $mail->ClearAddresses();
                    $mail->ClearAttachments();
                }

          
            }
   
 }
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Hotels With Offers</title>
<script language="Javascript" type="text/javascript" src="js/jquery-1.4.1.js"></script>
<script language="Javascript" type="text/javascript" src="js/misc.js"></script>
<link href="css/main.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/jquery.validate.js"></script>
<script language="javascript">
    $("#submit_details").validate({
                rules: {
                    user_password: "required",
                    confirm_password: {
                    equalTo: "#user_password"
                    }

                }
            });
   function check_member(member_email) {
        $.ajax({
        url: "extra_functions.php",
	type: "POST",
	cache: false,
        async:false,
	data: {member_email:member_email,member_check:true },
	success: function(theResponse)
	{
            if(theResponse == 'available'){
                $('#email_error').html('<span class="error">This email already exist in the system</span>');
                } else {
                    $('#email_error').html('');
                }
            }
         });
        }
</script>

</head>

<body>
<div id="wrapper">
    <?php require_once 'top_header.php'; ?>
        
<div class="contentPane">
  <div id="sidebar">
    <span class="menu"><img src="images/call.png" alt="Advertise with Hotel with Offers" class="callus"  /></span>
    <div class="joinus">
      <h1>INVITE A FRIEND</h1>
      <h2>Tell a friend and win Rs100.00</h2>
      <div class="joinbtn"><a href="#">LEARN&nbsp;MORE</a></div>
     </div>
    <div class="reserve"><span class="reserveitem">Reserved for :</span> <span class="reserveitem">advertising</span> <span class="reserveitem">latest news</span> <span class="reserveitem">soon ending deals &amp; offers</span></div>
  </div>
  <div class="leftPane">
    <div class="mainMenu"><?php require_once 'main_menu.php'; ?></div>
    <?php require_once 'newsletter_plug.php'; ?>
    <div>
    	<form id="submit_details" name="submit_details" method="post" action="sign-up.php">
              
              <div class="signUpForm">
        
          <div class="block">
			<?php echo isset($validation_error['first_name2'])?"<li class='error'>Please Enter your first name !</li>":""; ?>
			<p>First Name</p>
            <p>
              <input name="first_name2" class="field" id="first_name2" type="text" value="<?= isset($user_values['first_name2'])?$user_values['first_name2']:"";?>" />
            </p>
          </div>
          <div class="block">
			<?php echo isset($validation_error['last_name2'])?"<li class='error'>Please Enter your last name !</li>":""; ?>
            <p>Last Name</p>
            <p>
              <input name="last_name2" class="field" id="last_name2" type="text" value="<?= isset($user_values['last_name2'])?$user_values['last_name2']:"";?>"  />
            </p>
          </div>
          <div class="block">
			<?php echo isset($validation_error['user_email'])?$validation_error['user_email']:""; ?> <span id="email_error"></span>
            <p>Your Email</p>
            <p>
              <input name="user_email" class="field" id="user_email" value="<?= isset($user_values['user_email'])?$user_values['user_email']:"";?>" onblur="check_member(this.value);" type="text" />
              &nbsp; </p>
          </div>
          <div class="block">
            <?php echo isset($validation_error['user_password'])?$validation_error['user_password']:""; ?>
            <p>Password</p>
            <p>
              <input name="user_password" class="field" id="user_password" type="password" />
              &nbsp;  </p>
          </div>
          <div class="block">
            <?php echo isset($validation_error['confirm_password'])?$validation_error['confirm_password']:""; ?>
            <p>Confirm Password</p>
            <p>
              <input name="confirm_password" id="confirm_password" class="field" type="password" />
              &nbsp;  </p>
          </div>
          <div class="block">
            <?php echo isset($validation_error['contact_number2'])?$validation_error['contact_number2']:""; ?>
            <p>Phone Number</p>
            <p>
              <input name="contact_number2" id="contact_number2" type="text" value="<?= isset($user_values['contact_number2'])?$user_values['contact_number2']:"";?>" class="field" />
            
            </p>
          </div>
          <div class="block">
            <p>
              <input id="subscribe" name="subscribe" type="checkbox" checked="checked" value="1" title="Sign Up for HotelsWithOffers Newsletter" />
              &nbsp;Send me hotelswithoffers.com Offers </p>
          </div>
          <div class="block">
            <?php echo isset($validation_error['tc2'])?$validation_error['tc2']:""; ?>
            <p>
              <input <?= isset($user_values['tc2'])?"checked":"";?> id="tc2" name="tc2" type="checkbox"  value="1" title="Accept Terms and Conditions" />
              &nbsp;I aggreed to the <a href="#"> Terms and Conditions</a></p>
              
          </div>
          <div class="block"><?php echo $validation_error['image_code']; ?> <img src="securimage_show.php?sid=<?php echo md5(time()) ?>" alt="" align="left" id="siimage" style="padding-right: 5px; border: 0" />
            <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="19" height="19" id="SecurImage_as3" align="middle">
              <param name="allowScriptAccess" value="sameDomain" />
              <param name="allowFullScreen" value="false" />
              <param name="movie" value="securimage_play.swf?audio=securimage_play.php&amp;bgColor1=#777&amp;bgColor2=#fff&amp;iconColor=#000&amp;roundedCorner=5" />
              <param name="quality" value="high" />
              <param name="bgcolor" value="#ffffff" />
              <embed src="securimage_play.swf?audio=securimage_play.php&amp;bgColor1=#777&amp;bgColor2=#fff&amp;iconColor=#000&amp;roundedCorner=5" quality="high" bgcolor="#ffffff" width="19" height="19" name="SecurImage_as3" align="middle" allowscriptaccess="sameDomain" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></embed>
              </embed>
            </object>
            <br />
            <!-- pass a session id to the query string of the script to prevent ie caching -->
            <a tabindex="-1" style="border-style: none" href="#" title="Refresh Image" onclick="document.getElementById('siimage').src = 'securimage_show.php?sid=' + Math.random(); return false"><img src="images/refresh.gif" alt="Reload Image" border="0" onclick="this.blur()" align="bottom" /></a> <br class="clear" />
            <div class="block">
              <input type="text" name="image_code" id="image_code" value="Please type in the above code here" class="captcha" />
              <br/>
              </div>
          </div>
          <div class="block">
            <input class="signUpButton" name="signUpButton" value="Sign Up Now" type="submit" class="general_submit" />
          </div>

        </div>
    	</form>
    </div>      
    <div class="clear"></div>
</div>
</div>
<div class="clear"></div>
</div>
<div id="footerWrapper">
<div id="footer">
  <div class="leftllinks">
    <ul>
      <li><a href="#">getting started</a></li>
      <li><a href="#">hotel offers</a></li>
      <li><a href="#">great deals</a></li>
      <li><a href="#">tour packages</a></li>
      <li><a href="#">blog</a></li>
      <li><a href="#">support</a></li>
    </ul>
  </div>
  <div class="rightllinks">
    <ul>
      <li><a href="#">login</a></li>
      <li><a href="#">register</a></li>
      <li><a href="#">advertise with us</a></li>
      <li><a href="#">post your deals</a></li>
      <li><a href="#">post your hotel offers</a></li>
      <li><a href="#">contact us</a></li>
    </ul>
  </div>
  <div class="footerSocial"><a href="#"><img src="images/twt.png" alt="Tweet about Hotel with Offers" /></a><a href="#"><img src="images/fb.png" alt="Share Hotel with Offers on Facebook" /></a><a href="#"><img src="images/ln.png" alt="Connect Hotel with Offers with LinkedIn" /></a></div>
  <br class="clear" />
  <div class="copyright">© 2011 All Rights Reserved</div>
</div>
</div>
    
</body>
</html>
